/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package component.stylesheet.component;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author Administrator
 */
public class XlsLoaderProgress implements ChangeListener {

    JFrame frame = null;
    JProgressBar progressbar;
    JLabel label;
    JLabel b;
    private static boolean showB=true;

    public XlsLoaderProgress() {

       frame = new JFrame(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("EXCEL数据导入进度"));
       frame.setBounds(100, 100, 400, 130);
//       frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
       frame.setAlwaysOnTop(true);
       frame.setUndecorated(true);
       frame.setResizable(false);
       frame.setLocationRelativeTo(null);
       Container contentPanel = frame.getContentPane();
       label = new JLabel(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("当前文件读取："), JLabel.CENTER);
       progressbar = new JProgressBar();
       progressbar.setOrientation(JProgressBar.HORIZONTAL);
       progressbar.setMinimum(0);
       progressbar.setMaximum(100);
       progressbar.setValue(0);
       progressbar.setStringPainted(true);
       progressbar.addChangeListener(this);
       progressbar.setPreferredSize(new Dimension(300, 20));
       progressbar.setBorderPainted(true);
       progressbar.setBackground(Color.pink);
 
       JPanel panel = new JPanel();
       b = new JLabel(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("EXCEL文件正在读取"));
       b.setForeground(Color.ORANGE);
       panel.add(b);
       
       contentPanel.add(panel, BorderLayout.NORTH);
       contentPanel.add(label, BorderLayout.CENTER);
       contentPanel.add(progressbar, BorderLayout.SOUTH);
       // frame.pack();
       frame.setVisible(true);

    }

    public void stateChanged(ChangeEvent e1) {
       int value = progressbar.getValue();
       if (e1.getSource() == progressbar) {
           label.setText(java.text.MessageFormat.format(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("目前已完成进度：{0}%"), new Object[] {Integer.toString(value)}));
           label.setForeground(Color.blue);
           if(showB==false){
               frame.dispose();
           }
           if (value==100) {
              label.setText("正在等待地层数据最后的导入和处理"); 
           }
       }
    }
    public void setValue(int i){
        progressbar.setValue(i);
    }
    public void setShowB(boolean showB){
        this.showB=showB;
        frame.dispose();
    }
}